package com.smartwasser.yunhtgl.apphtgl.presenter;

import com.smartwasser.yunhtgl.apphtgl.bean.CaseProcess2Bean;
import com.smartwasser.yunhtgl.apphtgl.bean.CompanyBean;
import com.smartwasser.yunhtgl.apphtgl.network.RetrofitApi;
import com.smartwasser.yunhtgl.apphtgl.network.Retrofits;
import com.smartwasser.yunhtgl.apphtgl.view.CaseProcess2View;
import com.smartwasser.yunhtgl.apphtgl.utils.Logger;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class CaseProcess2PresenterImpl implements CaseProcess2Presenter {
    private CaseProcess2View caseProcess2View;

    public CaseProcess2PresenterImpl(CaseProcess2View caseProcess2View) {
        this.caseProcess2View = caseProcess2View;
    }

    /**
     * 已完成合同备案
     *
     * @param JSESSIONID
     * @param year
     * @param season
     * @param roleCode
     */
    @Override
    public void getMessages(final String JSESSIONID, String year, String season, String roleCode) {
        Retrofits.getInstance().createReq(RetrofitApi.class).getCaseProcess2(JSESSIONID, year, season, roleCode).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<CaseProcess2Bean>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                caseProcess2View.error();
                Logger.e("onError");
            }

            @Override
            public void onNext(final CaseProcess2Bean caseProcessBean) {
                caseProcess2View.success(caseProcessBean);
            }
        });
    }


    @Override
    public void getCompany(final String JSESSIONID) {
        Retrofits.getInstance().createReq(RetrofitApi.class).getCompany(JSESSIONID).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<CompanyBean>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                caseProcess2View.error();
                Logger.e("onError");
            }

            @Override
            public void onNext(CompanyBean companyBean) {
                caseProcess2View.successCompany(companyBean);
                Logger.e("onNext");
            }
        });
    }
}